package com.haiyi.software.app;

import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.AbstractWheelTextAdapter;
import kankan.wheel.widget.adapters.NumericWheelAdapter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;

public class ActivityNearbySearch extends Activity implements OnClickListener {

	private WheelView wheel_star_age;

	private WheelView wheel_end_age;

	CheckBox ck_sex_male, ck_sex_female, ck_sex_1, ck_sex_0, ck_sex_05,
			ck_sex_t, ck_sex_p, ck_sex_h, ck_sex_tc, ck_sex_bi, ck_sex_all;

	CheckBox boxs[] = new CheckBox[11];

	private Button btn_search_ok;

	private Button btn_search_cancel;

	private RadioButton radio_quarter, radio_onehour, radio_oneday,
			radio_threeday;

	private String str_appearTime = "15";

	private String str_sex = "-1";

	private String str_ageMax = "120";

	private String str_ageMin = "18";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO 自动生成的方法存根
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_nearby_search);

		initComp();

	}

	private void initComp() {
		// TODO 自动生成的方法存根
		this.wheel_end_age = (WheelView) this.findViewById(R.id.wheel_end_age);
		this.wheel_star_age = (WheelView) this
				.findViewById(R.id.wheel_star_age);

		this.wheel_end_age
				.setViewAdapter(new NumericWheelAdapter(this, 18, 120));

		this.wheel_star_age.setViewAdapter(new NumericWheelAdapter(this, 18,
				120));

		ck_sex_0 = (CheckBox) this.findViewById(R.id.ck_sex_0);
		ck_sex_05 = (CheckBox) this.findViewById(R.id.ck_sex_05);
		ck_sex_1 = (CheckBox) this.findViewById(R.id.ck_sex_1);
		ck_sex_female = (CheckBox) this.findViewById(R.id.ck_sex_female);
		ck_sex_h = (CheckBox) this.findViewById(R.id.ck_sex_h);
		ck_sex_male = (CheckBox) this.findViewById(R.id.ck_sex_male);
		ck_sex_p = (CheckBox) this.findViewById(R.id.ck_sex_p);
		ck_sex_t = (CheckBox) this.findViewById(R.id.ck_sex_t);
		ck_sex_bi = (CheckBox) this.findViewById(R.id.ck_sex_bi);
		ck_sex_tc = (CheckBox) this.findViewById(R.id.ck_sex_tc);
		ck_sex_all = (CheckBox) this.findViewById(R.id.ck_sex_all);

		this.radio_oneday = (RadioButton) this.findViewById(R.id.radio_oneday);
		this.radio_onehour = (RadioButton) this
				.findViewById(R.id.radio_onehour);
		this.radio_quarter = (RadioButton) this
				.findViewById(R.id.radio_quarter);
		this.radio_threeday = (RadioButton) this
				.findViewById(R.id.radio_threeday);

		this.btn_search_ok = (Button) this.findViewById(R.id.btn_search_ok);

		this.btn_search_cancel = (Button) this
				.findViewById(R.id.btn_search_cancel);

		this.btn_search_cancel.setOnClickListener(cancelClick);

		this.btn_search_ok.setOnClickListener(okClick);

		// this.wheel_end_age.setCyclic(true);
		// this.wheel_star_age.setCyclic(true);
		this.wheel_end_age.setVisibleItems(3);
		this.wheel_star_age.setVisibleItems(3);
		this.wheel_star_age.setCurrentItem(0);
		this.wheel_end_age.setCurrentItem(80);

		this.wheel_end_age.addScrollingListener(scrollListener);
		this.wheel_star_age.addScrollingListener(scrollListener);

		this.radio_oneday.setTag(1440);
		this.radio_onehour.setTag(60);
		this.radio_quarter.setTag(15);
		this.radio_threeday.setTag(4320);

		this.radio_oneday.setOnClickListener(radioClick);
		this.radio_onehour.setOnClickListener(radioClick);
		this.radio_quarter.setOnClickListener(radioClick);
		this.radio_threeday.setOnClickListener(radioClick);

		ck_sex_male.setTag("1");
		ck_sex_female.setTag("2");
		ck_sex_1.setTag("3");
		ck_sex_0.setTag("4");
		ck_sex_05.setTag("5");
		ck_sex_t.setTag("6");
		ck_sex_p.setTag("7");
		ck_sex_h.setTag("8");
		ck_sex_tc.setTag("9");
		ck_sex_bi.setTag("10");
		ck_sex_all.setTag("-1");

		boxs[0] = ck_sex_male;
		boxs[1] = ck_sex_female;
		boxs[2] = ck_sex_1;
		boxs[3] = ck_sex_0;
		boxs[4] = ck_sex_05;
		boxs[5] = ck_sex_t;
		boxs[6] = ck_sex_p;
		boxs[7] = ck_sex_h;
		boxs[8] = ck_sex_tc;
		boxs[9] = ck_sex_bi;
		boxs[10] = ck_sex_all;

		ck_sex_0.setOnClickListener(this);
		ck_sex_05.setOnClickListener(this);
		ck_sex_1.setOnClickListener(this);
		ck_sex_female.setOnClickListener(this);
		ck_sex_h.setOnClickListener(this);
		ck_sex_male.setOnClickListener(this);
		ck_sex_p.setOnClickListener(this);
		ck_sex_t.setOnClickListener(this);
		ck_sex_bi.setOnClickListener(this);
		ck_sex_tc.setOnClickListener(this);
		ck_sex_all.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {

		// TODO 自动生成的方法存根
		ck_sex_0.setChecked(false);
		ck_sex_05.setChecked(false);
		ck_sex_1.setChecked(false);
		ck_sex_female.setChecked(false);
		ck_sex_h.setChecked(false);
		ck_sex_male.setChecked(false);
		ck_sex_p.setChecked(false);
		ck_sex_bi.setChecked(false);
		ck_sex_t.setChecked(false);
		ck_sex_tc.setChecked(false);
		ck_sex_all.setChecked(false);

		((CheckBox) v).setChecked(true);
		str_sex = v.getTag().toString();

	}

	private OnClickListener okClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO 自动生成的方法存根

			str_ageMin = String.valueOf(wheel_star_age.getCurrentItem() + 18);

			str_ageMax = String.valueOf(wheel_end_age.getCurrentItem() + 18);

			Intent intent = new Intent();

			intent.putExtra("str_appearTime", str_appearTime);
			intent.putExtra("str_sex", str_sex);
			intent.putExtra("str_ageMax", str_ageMax);
			intent.putExtra("str_ageMin", str_ageMin);

			setResult(FragmentNearby.SHOW_ACTIVITY_SEARCH, intent);

			ActivityNearbySearch.this.finish();
		}
	};

	private OnClickListener cancelClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO 自动生成的方法存根
			ActivityNearbySearch.this.finish();
		}
	};

	private OnClickListener radioClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO 自动生成的方法存根
			str_appearTime = v.getTag().toString();
		}
	};

	private OnWheelScrollListener scrollListener = new OnWheelScrollListener() {

		@Override
		public void onScrollingStarted(WheelView wheel) {

		}

		@Override
		public void onScrollingFinished(WheelView wheel) {
			// TODO 自动生成的方法存根
			switch (wheel.getId()) {
			case R.id.wheel_star_age:
				str_ageMin = String.valueOf(wheel.getCurrentItem() + 18);
				break;

			case R.id.wheel_end_age:
				str_ageMax = String.valueOf(wheel.getCurrentItem() + 18);
				break;

			}
		}
	};

}
